<template>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router'
import { onMounted, inject } from "vue";
import { useStore } from 'vuex'

const route = useRoute()
const router = useRouter()
const store = useStore()
const api = inject('api')

const tenantCode = route.query.params || '1731596052865302530'
const redirect = route.query.redirect
const openid = route.query.openid
const projectId = route.query.projectId
const volunteer = route.query.volunteer

sessionStorage.removeItem('volunteer')
sessionStorage.setItem('tenantCode', tenantCode);
openid && sessionStorage.setItem('openid', openid);
projectId && sessionStorage.setItem('projectId', projectId);
volunteer && sessionStorage.setItem('volunteer', volunteer);
// sessionStorage.setItem('isScan', true);

function load () {
  if (!tenantCode) {
    router.replace('/404')
    return
  }

  api.getTenantCodeConfig(tenantCode).then(res => {
    if (!res.code) {
      store.commit('tenant/SET_CONFIG', res.data)
      router.replace({
        path: redirect,
        query: route.query
      })
    }
  })
}
onMounted(() => {
  load ()
})
</script>
